<?php

/**
 * This is the model class for table "formadepago".
 *
 * The followings are the available columns in table 'formadepago':
 * @property integer $idFormadepago
 * @property string $descripcion
 * @property integer $tarjeta_credito
 * @property integer $anticipo
 * @property string $p_anticipo
 * @property integer $n_cuotas
 * @property integer $f_cuotas
 * @property integer $banco
 *
 * The followings are the available model relations:
 * @property Cliente[] $clientes
 * @property Cajaybanco $banco0
 * @property Proveedor[] $proveedors
 * @property Venta[] $ventas
 */
class Formadepago extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'formadepago';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('descripcion', 'required'),
			array('tarjeta_credito, anticipo, n_cuotas, f_cuotas, banco', 'numerical', 'integerOnly'=>true),
			array('descripcion', 'length', 'max'=>45),
			array('p_anticipo', 'length', 'max'=>10),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('idFormadepago, descripcion, tarjeta_credito, anticipo, p_anticipo, n_cuotas, f_cuotas, banco', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'clientes' => array(self::HAS_MANY, 'Cliente', 'forma_pago'),
			'banco0' => array(self::BELONGS_TO, 'Cajaybanco', 'banco'),
			'proveedors' => array(self::HAS_MANY, 'Proveedor', 'forma_pago'),
			'ventas' => array(self::HAS_MANY, 'Venta', 'forma_cobro'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idFormadepago' => 'Id Formadepago',
			'descripcion' => 'Descripcion',
			'tarjeta_credito' => 'Tarjeta Credito',
			'anticipo' => 'Anticipo',
			'p_anticipo' => 'P Anticipo',
			'n_cuotas' => 'N Cuotas',
			'f_cuotas' => 'F Cuotas',
			'banco' => 'Banco',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idFormadepago',$this->idFormadepago);
		$criteria->compare('descripcion',$this->descripcion,true);
		$criteria->compare('tarjeta_credito',$this->tarjeta_credito);
		$criteria->compare('anticipo',$this->anticipo);
		$criteria->compare('p_anticipo',$this->p_anticipo,true);
		$criteria->compare('n_cuotas',$this->n_cuotas);
		$criteria->compare('f_cuotas',$this->f_cuotas);
		$criteria->compare('banco',$this->banco);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Formadepago the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
